﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
using System.Data;
using System.Windows.Forms;
using System.IO;
namespace BLLA
{
    public partial class Order_Mer_T : BaseBLL<Model.Order_Mer_T>, IBLL.IOrder_Mer_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();
        /// <summary>
        /// 获取商户图片
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式(1:json;2:xml)</param>
        /// <returns></returns>
        public byte[] GetPhoto(string MerID, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                return null;
            }
            #endregion
            List<Model.Order_Mer_T> list_tmp1 = base.GetListBy(u => u.MerID == MerID);
            if (list_tmp1 != null && list_tmp1.Count > 0)
            {
                Model.Order_Mer_T tmp = list_tmp1.First();
                string fileName = tmp.MerPic;
                FileStream fs = new FileStream(@"D:\开发\用户管理中心\网上订餐系统服务代码\HOST\bin\Debug\Photo\MerPhoto\10.jpg", FileMode.Open, FileAccess.Read);
                try
                {
                    byte[] buffur = new byte[fs.Length];
                    fs.Read(buffur, 0, (int)fs.Length);
                    return buffur;
                }
                catch (Exception ex)
                {

                    return null;
                }
                finally
                {
                    if (fs != null)
                    {
                        //关闭资源  
                        fs.Close();
                    }
                }
            }
            else
            {
                return null;
            }

        }
        /// <summary>
        /// 更新商户图片
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="Pic">商户图片字节流</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式(1:json;2:xml)</param>
        /// <returns></returns>
        public string UpdateMerPhoto(string MerID, byte[] Pic, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                string name = Application.StartupPath + "\\Photo\\MerPhoto\\" + MerID + ".jpg";
                File.WriteAllBytes(name, Pic);
                int ret = -1;
                List<Model.Order_Mer_T> list_tmp1 = base.GetListBy(u => u.MerID == MerID);
                if (list_tmp1 != null && list_tmp1.Count > 0)
                {
                    Model.Order_Mer_T tmp = list_tmp1.First();
                    tmp.MerPic = Help.ALL_DataV.PhotoPath + "/MerPhoto/" + MerID + ".jpg";
                    ret = base.Modify(tmp);
                }
                if (ret > 0)
                {
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新商户图片失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商户图片失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "更新商户图片失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }
        /// <summary>
        /// 获取商户当前上架列表
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式(1:json;2:xml)</param>
        /// <returns></returns>
        public string GetShelvesInfo(string MerID, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务层
            List<Model.ShelvesInfo> ls = new List<Model.ShelvesInfo>();
            try
            {
                string time = DateTime.Now.ToString("HHmm");
                int day = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
                List<Model.Order_Shelves_T> tmp = base.DBSession.IOrder_Shelves_TDAL.GetListBy("SELECT *  FROM  Order_Shelves_T where MerID='" + MerID + "' and  SheTimeB <='" + time + "' and SheTimeE>='" + time + "' and SheDateB<='" + day + "' and SheDateE>='" + day + "' and SheState=1 ");
                if (tmp.Count > 0)
                {
                    #region MyRegion
                    // string[] she=  tmp[0].DishesID.Split(',');
                    int zzb = tmp[0].SheID;
                    List<Model.View_Order_Dishes> dishlist = base.DBSession.IView_Order_DishesDAL.GetListBy("SELECT *  FROM View_Order_Dishes where DishesID in (" + tmp[0].DishesID + ")");
                    List<Model.Order_Sales_T> list = base.DBSession.IOrder_Sales_TDAL.GetListBy(u => u.SalesDate == day & u.SheID == zzb);
                    if (list.Count > 0)
                    {
                        foreach (Model.View_Order_Dishes item in dishlist)
                        {
                            Model.ShelvesInfo ss = new ShelvesInfo();
                            ss.DishInfo = item;
                            ss.HaveNub = (from m in list where m.DishesID == item.DishesID select m).ToList().First().HaveNub;
                            ss.SaleNub = (from m in list where m.DishesID == item.DishesID select m).ToList().First().SalesNub;
                            ls.Add(ss);

                        }
                    }
                    else
                    {
                        string[] ShelveDishIDS = tmp[0].DishesID.Split(',');
                        string[] ShelveNumS = tmp[0].DishesNub.Split(',');
                        List<Model.Order_Sales_T> SaleList = new List<Model.Order_Sales_T>();
                        for (int i = 0; i < ShelveDishIDS.Length; i++)
                        {
                            Model.Order_Sales_T Sale = new Model.Order_Sales_T();
                            Sale.SheID = tmp[0].SheID;
                            Sale.DishesID = ShelveDishIDS[i];
                            Sale.SalesNub = int.Parse(ShelveNumS[i]);
                            Sale.HaveNub = Sale.SalesNub;
                            Sale.IntTime = time;
                            Sale.SalesDate = day;
                            Sale.SheState = 1;
                            Sale.BZ = "";
                            SaleList.Add(Sale);
                        }
                        base.DBSession.IOrder_Sales_TDAL.Add(SaleList);

                        foreach (Model.View_Order_Dishes item in dishlist)
                        {
                            Model.ShelvesInfo ss = new ShelvesInfo();
                            ss.DishInfo = item;
                            ss.HaveNub = (from m in SaleList where m.DishesID == item.DishesID select m).ToList().First().HaveNub;
                            ss.SaleNub = (from m in SaleList where m.DishesID == item.DishesID select m).ToList().First().SalesNub;
                            ls.Add(ss);
                        }
                    }
                    #endregion
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据！";
                    return os.StringOfObject(result, RETID);
                }
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }
            result.BS = "1";
            result.Msg = "查询成功！";
            result.total = ls.Count;
            result.rows = ls;

            return os.StringOfObject(result, RETID);
            #endregion
        }

        /// <summary>
        /// 查询商户
        /// </summary>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetOrder_Mer(string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务层
            List<Model.View_Order_MerSet> mo = new List<Model.View_Order_MerSet>();
            try
            {
                mo = base.DBSession.IView_Order_MerSetDAL.GetListBy("SELECT * FROM View_Order_MerSet where  MerState=1");
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }
            result.BS = "1";
            result.Msg = "查询成功！";
            result.total = mo.Count;
            result.rows = mo;

            return os.StringOfObject(result, RETID);
            #endregion
        }


        /// <summary>
        /// 更新商户信息信息（当商户内有商品后就不允许删除）
        /// </summary>
        /// <param name="OperID">操作员ID</param>
        /// <param name="UserWaltID">用户钱包ID</param>
        /// <param name="updateMoney">金额</param>
        /// <param name="BZ">备注</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string SetOrder_Mer(int OperID, string json, int tag, string YZM, int RETID)
        {
            WriteLog.WriteW("进入更新商户信息 SetOrder_Mer(" + OperID + "," + json + "," + tag + "," + YZM + "," + RETID + ")");
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                Model.Order_Mer_T info = ParseClass<Model.Order_Mer_T>.StrDeserialize(json, RETID);
                string T = "";
                int ret = -1;
                // 根据操作标签Tag判断是什么操作
                switch (tag)
                {
                    case 1:
                        T = "新增";
                        info.MerSort = "1@";
                        info.MerID = GetSysKey.GetKey("MerKey");
                        ret = base.Add(info);
                        break;
                    case 2:
                        T = "修改";
                        Model.Order_Mer_T tmp = base.GetListBy(u => u.MerID == info.MerID).First();
                        Help.FuZhi<Model.Order_Mer_T>.FZ(ref tmp, info);
                        ret = base.Modify(tmp);
                        break;
                    case 3:
                        T = "删除";
                        List<Model.Order_Mer_T> list_tmp = base.GetListBy(u => u.MerID == info.MerID);
                        if (list_tmp != null && list_tmp.Count > 0)
                        {
                            tmp = list_tmp.First();
                            tmp.MerState = 0;
                            ret = base.Modify(tmp);
                        }

                        //去掉用户操作表里已被删除的Merid
                        string merid = list_tmp.First().MerID;
                        List<Model.Order_Oper_T> operList = base.DBSession.IOrder_Oper_TDAL.GetListBy(u => u.MerID.Contains(merid)).ToList();
                        if (operList.Count > 0)
                        {
                            char[] cha = new char[1] { ',' };
                            foreach (var item in operList)
                            {
                                string[] omer = item.MerID.Split(cha).Where(o => o.Contains(merid)).ToArray();
                                if (omer.Count() > 0)
                                {
                                    string[] olMerid = item.MerID.Split(cha).Where(o => o != merid).ToArray();
                                    item.MerID = String.Join(",", olMerid);
                                    int bdm = base.DBSession.IOrder_Oper_TDAL.Modify(item);
                                    if (bdm <= 0)
                                    {
                                        WriteLog.WriteW("SetOrder_Mer      去掉用户操作表里已被删除的Merid失败");
                                    }
                                }

                            }
                        }

                        break;
                }

                if (ret > 0)
                {
                    // 将操作记录到日志表中
                    Model.Order_OperationFlow_T Log = new Model.Order_OperationFlow_T();
                    Log.OperationTitle = "更改商户信息";
                    Log.OperationText = T + "商户信息成功";
                    Log.OperationType = "1F0006";
                    Log.OperationRes = "成功";
                    Log.OperationUser = OperID;
                    string str_log = os.StringOfObject(Log, RETID);
                    bool isSuccess = new Order_OperationFlow_T().AddOrder_OperationFlow(str_log, RETID);
                    if (!isSuccess)
                    {
                        WriteLog.WriteW("新增系统操作流水失败");
                    }
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商户信息失败：" + ex.Message);
                result.BS = "-1";
                result.Msg = "更新失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }

        /// <summary>
        /// 商户的分类、排序、查询
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="KeyWord">商户名称</param>
        /// <param name="FenLei">商户分类</param>
        /// <param name="PaiXu">（DictKey）-Basic_Dict_T.DictId=34</param>
        /// <param name="DelMaxMon">0元起送 0：否 1：是</param>
        /// <param name="DelFormMon">免配送 0：否 1：是</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetShopList(int pageIndex, int pageSize, string KeyWord, string FenLei, int PaiXu, int DelMaxMon, int DelFormMon, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 业务层

            List<Model.View_Order_MerSet> mo = new List<Model.View_Order_MerSet>();
            try
            {
                //try
                //{
                //    mo = base.DBSession.IView_Order_MerSetDAL.GetListBy(u => u.MerState == 1);
                //}

                //catch (Exception)
                //{
                //    result.BS = "-1";
                //    result.Msg = "查询不到数据！";
                //    return os.StringOfObject(result, RETID);
                //}
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM View_Order_MerSet where MerState='1'");
                if (KeyWord != "")
                {
                    sql.Append(" and  MerName like '%" + KeyWord + "%' ");
                    //mo = (from c in mo where c.MerName.Contains(KeyWord) select c).ToList();
                }
                if (FenLei != "")
                {
                    sql.Append(" and  DelType = '" + FenLei + "' ");
                    //mo = (from c in mo where c.DelType == FenLei select c).ToList();
                }
                if (DelMaxMon == 1)
                {
                    sql.Append(" and  DelMaxMon =0");
                    // mo = (from c in mo where c.DelMaxMon == 0 select c).ToList();
                }
                if (DelFormMon == 1)
                {
                    sql.Append(" and  DelFormMon =0");
                    //mo = (from c in mo where c.DelFormMon == 0 select c).ToList();
                }
                //if (DelPackMon == 1)
                //{
                //    mo = (from c in mo where c.DelPackMon == 0 select c).ToList();
                //}
                mo = base.DBSession.IView_Order_MerSetDAL.GetListBy(sql.ToString());
                switch (PaiXu)
                {
                    case 0:
                        #region MyRegion
                        string str_排序 = base.DBSession.IOrder_Key_TDAL.GetListBy(u => u.ID > 0).First().TopMer;
                        switch (str_排序.Substring(0, 1))
                        {
                            case "0":
                                string[] IdList = str_排序.Split('@')[1].Split(',');
                                List<Model.View_Order_MerSet> tmplist = new List<Model.View_Order_MerSet>();
                                foreach (string item in IdList)
                                {
                                    try
                                    {
                                        Model.View_Order_MerSet tm = (from c in mo where c.MerID == item select c).ToList().First();
                                        tmplist.Add(tm);
                                    }
                                    catch (Exception)
                                    {

                                    }
                                }
                                mo = tmplist;
                                break;
                            case "1":
                                mo.Sort((x, y) =>
                                {
                                    return y.SalesCount.CompareTo(x.SalesCount);
                                });
                                break;
                            case "2":
                                mo.Sort((x, y) =>
                                {
                                    return y.EvaCount.CompareTo(x.EvaCount);
                                });
                                break;
                            default:
                                try
                                {

                                    mo = (from m in mo orderby (m.StarCount / m.SalesCount) descending select m).ToList();
                                }
                                catch (Exception)
                                {

                                }
                                break;
                        }
                        #endregion
                        break;
                    case 1:
                        mo.Sort((x, y) =>
                        {
                            return y.SalesCount.CompareTo(x.SalesCount);
                        });
                        break;
                    case 2:
                        mo.Sort((x, y) =>
                        {
                            return y.EvaCount.CompareTo(x.EvaCount);
                        });
                        break;
                    default:
                        List<Model.View_Order_MerSet> noSales = mo.Where(m => m.EvaCount == 0).ToList();
                        mo = (from m in mo.Where(m => m.EvaCount > 0) orderby (Convert.ToDouble(m.StarCount) / Convert.ToDouble(m.EvaCount)) descending select m).ToList();
                        mo.AddRange(noSales);
                        break;
                }
                result.total = mo.Count;
                mo = mo.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();

                result.BS = "1";
                result.Msg = "查询成功！";
                result.rows = mo;

                return os.StringOfObject(result, RETID);
            }
            catch (Exception)
            {
                result.BS = "-99";
                result.Msg = "数据异常！";
                return os.StringOfObject(result, RETID);
            }

            #endregion
        }
        /// <summary>
        /// 获取商户所有信息，包括简介，配送时间，商品信息等等
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetShopInfo(string MerID, string YZM, int RETID)
        {
            WriteLog.WriteW("GetShopInfo:" + MerID);
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
          
            #region 业务层
            Order_ShopInfo mo = new Order_ShopInfo();
            try
            {

                mo.ShopInfo = base.DBSession.IView_Order_MerSetDAL.GetListBy("SELECT * FROM View_Order_MerSet where MerID='" + MerID + "'").First();
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("GetShopInfo:" + ex.Message);
                result.BS = "-1";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }
            try
            {
                WriteLog.WriteW("GetShopInfo:拿类型" + MerID);
                mo.TypeList = base.DBSession.IOrder_DishesType_TDAL.GetListBy("SELECT * FROM View_Order_DishesType where MerID='" + MerID + "'");
                WriteLog.WriteW("GetShopInfo:拿类型1" + mo.TypeList.Count);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("GetShopInfo:" + ex.Message);
                result.BS = "-2";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }
            try
            {
                WriteLog.WriteW("GetShopInfo测试" + 0);
                string time = DateTime.Now.ToString("yyyyMMddHHmm");
                WriteLog.WriteW("GetShopInfo测试" + 0);
                string day = time.Substring(0, 8);
                string tm = time.Substring(8, 4);
                WriteLog.WriteW("GetShopInfo测试"+1 );
                //List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(u => u.SheDateB < day & u.SheDateE > day & u.MerID == MerID & u.SheState == 1);

                // List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(u => u.SheState == 1);
                string sql = "SELECT * FROM Order_Shelves_T where SheDateB<=" + day + " and SheDateE>=" + day + " and MerID='" + MerID + "' and  SheTimeB<'" + tm + "' and SheTimeE > '" + tm + "' and SheState=1";
                List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(sql);
                WriteLog.WriteW("GetShopInfo测试" + 2);
                if (ShelList.Count > 0)
                {
                    mo.DishList = base.DBSession.IView_Order_DishesDAL.GetListBy("SELECT * FROM View_Order_Dishes where MerID='" + MerID + "' and DishesID in (" + ShelList[0].DishesID + ") and DishesTypeState=1");
                    WriteLog.WriteW("GetShopInfo测试" + 3);
                    List<Model.View_Order_Dishes> LS = base.DBSession.IView_Order_DishesDAL.GetListBy("SELECT * FROM View_Order_Dishes where MerID='" + MerID + "' and DishesID not in (" + ShelList[0].DishesID + ") and DishesTypeState=1");
                    WriteLog.WriteW("GetShopInfo测试" + 4);
                    List<Model.Order_Sales_T> sl = base.DBSession.IOrder_Sales_TDAL.GetListBy("SELECT * FROM Order_Sales_T where  SheID='" + ShelList[0].SheID + "' and DishesID in (" + ShelList[0].DishesID + ") and SalesDate = " + day + "");
                    WriteLog.WriteW("GetShopInfo测试" + 5);
                    if (sl.Count == 0)
                    {
                        string[] ShelveDishIDS = ShelList[0].DishesID.Split(',');
                        string[] ShelveNumS = ShelList[0].DishesNub.Split(',');
                        sl = new List<Model.Order_Sales_T>();
                        for (int i = 0; i < ShelveDishIDS.Length; i++)
                        {
                            Model.Order_Sales_T Sale = new Model.Order_Sales_T();
                            Sale.SheID = ShelList[0].SheID;
                            Sale.DishesID = ShelveDishIDS[i];
                            Sale.SalesNub = int.Parse(ShelveNumS[i]);
                            Sale.HaveNub = Sale.SalesNub;
                            Sale.IntTime = time;
                            Sale.SalesDate = int.Parse(day);
                            Sale.SheState = 1;
                            Sale.BZ = "";
                            sl.Add(Sale);
                        }
                        base.DBSession.IOrder_Sales_TDAL.Add(sl);
                    }
                    StringBuilder cstr = new StringBuilder();
                    foreach (var item in sl)
                    {
                        cstr.Append("," + item.HaveNub);
                    }
                    foreach (var item in LS)
                    {
                        mo.DishList.Add(item);
                        cstr.Append(",0");
                    }
                    cstr.Remove(0, 1);
                    mo.CountArr = cstr.ToString().Split(',');
                }
                else
                {
                    sql = "SELECT * FROM Order_Shelves_T where SheDateB<=" + day + " and SheDateE>=" + day + " and MerID='" + MerID + "'  and SheState=1";
                    ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(sql);
                    if (ShelList.Count > 0)
                    {
                        result.BS = "-4";
                        string strtime = "";
                        foreach (var item in ShelList)
                        {
                            strtime += item.SheTimeB.Substring(0, 2) + ":" + item.SheTimeB.Substring(2, 2) + " 至" + item.SheTimeE.Substring(0, 2) + ":" + item.SheTimeE.Substring(2, 2) +"\n";
                        }
                        result.Msg = "请在" + strtime + "之间点餐";

                    }
                    else
                    {
                        result.BS = "-5";
                        result.Msg = "餐厅没有营业";
                    }
                    return os.StringOfObject(result, RETID);
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("GetShopInfo-3:" + ex.Message);
                //result.BS = "-3";
                //result.Msg = "查询不到数据！";
                //return os.StringOfObject(result, RETID);
            }
            try
            { 
                mo.PricList = base.DBSession.IView_Order_MerPricingDAL.GetListBy(u => u.MerID == MerID & u.PricState == 1); 
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("GetShopInfo:" + ex.Message);
                result.BS = "-6";
                result.Msg = "查询不到数据！";
                return os.StringOfObject(result, RETID);
            }
            result.BS = "1";
            result.Msg = "查询成功！";
            result.total = 1;
            result.rows = mo;

            return os.StringOfObject(result, RETID);
            #endregion
        }



        /// <summary>
        /// 根据操作员ID获取商户
        /// </summary>
        /// <param name="OperID">操作员ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetOrder_MerByOperId(int OperID, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            try
            {
                #region 业务层
                string[] MerIdS = base.DBSession.IOrder_Oper_TDAL.GetListBy(u => u.OperID == OperID).First().MerID.Split(',');
                List<Model.View_Order_MerSet> mo = new List<Model.View_Order_MerSet>();
                try
                {
                    mo = base.DBSession.IView_Order_MerSetDAL.GetListBy(u => u.MerState == 1 & MerIdS.Contains(u.MerID));
                }
                catch (Exception)
                {
                    result.BS = "-1";
                    result.Msg = "查询不到数据！";
                    return os.StringOfObject(result, RETID);
                }
                result.BS = "1";
                result.Msg = "查询成功！";
                result.total = mo.Count;
                result.rows = mo;

                return os.StringOfObject(result, RETID);

                #endregion
            }
            catch (Exception ex)
            {
                result.BS = "-99";
                result.Msg = "数据异常！" + ex.Message;

                return os.StringOfObject(result, RETID);
            }


        }


        #region 更新图片
        /// <summary>
        /// 更新图片
        /// </summary>
        /// <param name="DishesID"></param>
        /// <param name="PhotoAdd"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string SetMerPhoto(string MerID, string PhotoAdd, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                int ret = -1;
                List<Model.Order_Mer_T> list_tmp1 = base.GetListBy(u => u.MerID == MerID);
                if (list_tmp1 != null && list_tmp1.Count > 0)
                {
                    Model.Order_Mer_T tmp = list_tmp1.First();
                    tmp.MerPic = PhotoAdd;
                    ret = base.Modify(tmp);
                }
                if (ret > 0)
                {
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新商品图片失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商品图片失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "更新商品图片失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }
        #endregion
    }
}
